use "${clean}analysis.dta", clear

keep if south == 1 
drop if congress > 55

// keeping only democrats
keep if partyid == 0

//standardizing variables
egen birth_county_surban = std(birth_county_urban_percent)
egen birth_county_srugged = std(birth_county_ruggedness)
egen birth_county_spostoffice = std(birth_county_postoffice_area)
egen sborn = std(born)

// creating a variable to keep the sample constant
cap drop sample
gen sample = 1
foreach var of varlist $county_bcontrols $life_controls {
	replace sample = . if `var' == .
}
keep if sample == 1

// variables
replace year = year - 1860
gen period = year > 0
gen interact = year*period

// estimates
estimates clear

eststo: mixed singular year i.period interact ${county_bcontrols} ${life_controls} if sample == 1 || _all:R.congress || bioguide_id: 

eststo: mixed singular year i.period ${county_bcontrols} ${life_controls} if sample == 1 || _all:R.congress || bioguide_id: 

eststo: mixed singular year ${county_bcontrols} ${life_controls} if sample == 1 || _all:R.congress || bioguide_id: 

esttab est* using "${output}TabS2_congress_southdem_fulltable.tex", replace ///
	b(%8.3f) se(%8.3f) transform(ln*: exp(@) exp(@)) ///
	starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	keep( ///
		year ///
		0.period 1.period ///
		interact ///
		birth_county_surban birth_county_spostoffice birth_county_srugged birth_county_anyriver birth_county_anycanal ///
		sborn college usmilitary ///
		_cons) ///
	order( ///
		year ///
		0.period 1.period ///
		interact ///
		birth_county_surban birth_county_spostoffice birth_county_srugged birth_county_anyriver birth_county_anycanal ///
		sborn college usmilitary ///
		_cons) ///
	coeflabels( ///
		year "Year of Speech" ///
		0.period "Pre-War" ///
		1.period "Post-Reconstruction" ///
		interact "Year $\times$ Post-Reconstruction" ///	
		birth_county_surban "County of Birth: \% Urban (std)" /// 
		birth_county_spostoffice "County of Birth: Post Office Density (std)" ///
		birth_county_srugged "County of Birth: Terrain Ruggedness (std)" ///
		birth_county_anyriver "Born on River" ///
		birth_county_anycanal "Born on Canal" ///
		sborn "Year of Birth (std)" ///
		college "Attended College" ///
		usmilitary "Served in US Military" ///
		_cons "Constant" ///
		) ///
	nodepvars nomtitles nonotes ///
	eqlabels("" "sd(Congress)" "sd(Bioguide)" "sd(Residual)", none) ///
	nogaps nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	
